package org.example.factory;

import cn.hutool.core.io.FileUtil;
import org.springframework.stereotype.Component;

import java.io.File;
import java.nio.charset.Charset;
import java.util.Map;

/**
 * @Description:
 * @Date: 2025/8/6 09:06
 */
@Component
public class MysqlTypeFactory extends DockerFileTypeFactory{
    @Override
    public String getDockerFileType() {
        return "mysql";
    }

    @Override
    public String getDockerFilePath() {
        return System.getProperty("user.dir") + "/docker/mysql8/dockerfile";
    }

    @Override
    public String getImageName() {
        return "ddm_mysql";
    }

    @Override
    public Map<String, String> dealWithBuildArgMap(Map<String, Object> params) {
        String userDir = System.getProperty("user.dir");
        Map<String, String> buildArgMap =(Map<String, String>) params.get("buildArgMap");
        Object businessTableSql = params.get("businessTableSql");
        Object ddmSql = params.get("ddmSql");
        File systemFile = FileUtil.file(userDir + "/docker/mysql8/system.sql");
        File initFile = FileUtil.file(userDir + "/docker/mysql8/init.sql");
        FileUtil.copy(systemFile, initFile, true);
        FileUtil.appendString((String) businessTableSql, initFile, "UTF-8");
        FileUtil.appendString((String) ddmSql, initFile, "UTF-8");
        return buildArgMap;
    }
}
